Lan Chatting system [closed]
Posted
by jay prakash singh
on Stack Overflow
See other posts from Stack Overflow
or by jay prakash singh
Published on 2010-05-11T15:37:32Z
Indexed on
2010/05/11
16:44 UTC
Read the original article
Hit count: 285
Possible Duplicate:
LAN chating system or LAN chat server
displaying list of user to all the user window my code is i m use RMI so this is the interface declaration
public void sendPublicMessage(String keyword, String username, String message) throws RemoteException;
public void sendPrivateMessage(String keyword, String username, String message) throws RemoteException;
public ArrayList getClientList() throws RemoteException;
public void connect(String username) throws RemoteException;
public void disconnect(String username) throws RemoteException;
}
chat Server here connectedUser is the HasMap object we use the follo0wing code for connection here ChatImpl is the stub
try
{
InetAddress Address = InetAddress.getLocalHost();
ChatImpl csi = new ChatImpl(this);
Naming.rebind("rmi://"+Address.getHostAddress()+":1099/ChatService", csi);
}
public ArrayList getClientList()
{
ArrayList myUser = new ArrayList();
Iterator i = connectedUser.keySet().iterator();
String user = null;
while(i.hasNext())
{
user = i.next().toString();
myUser.add(user);
}
return myUser;
}
public void addClient(Socket clientSocket) throws RemoteException
{
connectedUser.put(getUsername(), clientSocket);
sendPublicMessage(ONLINE, getUsername(), "CLIENT");
}
this is the client side code for array list
public void updateClient(ArrayList allClientList) throws RemoteException
{
listClient.clear();
int i = 0;
String username;
for(i=0; i<allClientList.size(); i++)
{
username = allClientList.get(i).toString();
listClient.addElement(username);
}
}
© Stack Overflow or respective owner